package com.nova.bluetooth.ui.device;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.nova.bluetooth.R;
import com.nova.bluetooth.base.BaseFragment;
import com.nova.bluetooth.databinding.FragmentDeviceTabBinding;
import com.nova.bluetooth.helpUtils.OnClickEvent;
import com.nova.bluetooth.helpUtils.ToastUtils;
import com.nova.bluetooth.manage.BluetoothHelper;
import com.nova.bluetooth.ui.bluetoothDemo.MainActivity;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class DeviceTabFragment extends BaseFragment {
    private FragmentDeviceTabBinding binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_device_tab, container, false);
        binding = FragmentDeviceTabBinding.bind(view);
        initView();
        return binding.getRoot();
    }

    private void initView() {
       binding.llManagerDevice.setOnClickListener(onClickEvent);
       binding.tvToScanDevice.setOnClickListener(onClickEvent);
       binding.tvManagerConnected.setOnClickListener(onClickEvent);
    }

    @Override
    public void onResume() {
        super.onResume();

        checkConnectedDevice();
    }

    private void checkConnectedDevice(){
        if (BluetoothHelper.getInstance().isConnected()){
            binding.tvDeviceName.setText(BluetoothHelper.getmConnectedBleDevice().getName());
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }


    private final OnClickEvent onClickEvent = new OnClickEvent() {
        @Override
        public void singleClick(View v) {
            if (v.getId() == R.id.ll_manager_device){
                startActivity(new Intent(getActivity(), MainActivity.class));

//                DeviceContainerActivity.startThisActivity(getActivity(),
//                        DeviceContainerActivity.FRAGMENT_TAG_FIND_DEVICE);
            }else if (v.getId() == R.id.tv_to_scan_device){
                startActivity(new Intent(getActivity(), AppScanBluetoothActivity.class));
            }else if (v.getId() == R.id.tv_manager_connected){
//                startActivity(new Intent(getActivity(), ConnectedListActivity.class));
            }
        }
    };
}
